#include "stdafx.h"

namespace AirCrash {
namespace Calypso {

QSettings * Config::mConfig = 0;

void Config::create() {
#ifndef NDEBUG
	QFile::remove("config.ini");
#endif

	mConfig = new QSettings("config.ini", QSettings::IniFormat);
	if (!mConfig->contains("Database/type")) {
		mConfig->setValue("Database/type", "SQLite");

		mConfig->setValue("Image/previousButtonNormal", "images/normal.png");
		mConfig->setValue("Image/previousButtonHover", "images/Hover.png");
		mConfig->setValue("Image/previousButtonPressed", "images/Pressed.png");
		mConfig->setValue("Image/nextButtonNormal", "images/normal.png");
		mConfig->setValue("Image/nextButtonHover", "images/Hover.png");
		mConfig->setValue("Image/nextButtonPressed", "images/Pressed.png");
		
		mConfig->setValue("Background/image", "images/BackTombola.png");
		mConfig->setValue("Background/color", "#2d2c2c");

		mConfig->setValue("Image/maxSize", QSize(1180, 664));
		mConfig->setValue("Image/overlayType", "Text");
		mConfig->setValue("Image/overlayPos", QRect(0, 614, 1180, 50));
		mConfig->setValue("Image/overlayAlign", Qt::AlignCenter);
		mConfig->setValue("Image/overlayText", "Showband Calypso dankt u voor uw steun");
		mConfig->setValue("Image/overlayTextColor", "white");
		mConfig->setValue("Image/overlayTextSize", 30);
		mConfig->setValue("Image/overlayImage", "");

		mConfig->setValue("Layout/previousButton", QRect(40, 40, 260, 120));
		mConfig->setValue("Layout/nextButton", QRect(980, 40, 260, 120));
		mConfig->setValue("Layout/codeArea", QRect(320, 40, 640, 120));
		mConfig->setValue("Layout/summaryArea", QRect(40, 180, 1200, 100));
		mConfig->setValue("Layout/imageArea", QRect(50, 310, 1180, 664));
		mConfig->setValue("Layout/totalArea", QRect(40, 984, 118, 40));
		mConfig->setValue("Layout/totalFontSize", 20);

		mConfig->setValue("Settings/allowNextDay", false);
		mConfig->setValue("Settings/fullScreen", true);
		mConfig->setValue("Settings/allowShutdown", false);
		mConfig->setValue("Settings/backupImages", true);
		mConfig->setValue("Settings/waitTimeScannedCode", 2000);
		mConfig->setValue("Settings/timeToNew", 30);
		mConfig->setValue("Settings/webcamEnabled", true);

#ifndef NDEBUG
		mConfig->setValue("Settings/hideMouse", false);
#else
		mConfig->setValue("Settings/hideMouse", true);
#endif

		mConfig->setValue("Webcam/width", 1024);
		mConfig->setValue("Webcam/height", 768);

		mConfig->setValue("Time/area", QRect(980, 924, 320, 60));
		mConfig->setValue("Time/fontSize", 40);
		mConfig->setValue("Time/format", "hh:mm");

		mConfig->setValue("Numpad/area", QRect(0, 170, 1280, 854));
		mConfig->setValue("Numpad/imagePath", "images/Numpad");
		mConfig->setValue("Numpad/imageExt", ".jpg");
		mConfig->setValue("Numpad/7", QRect(401, 9, 152, 193));
		mConfig->setValue("Numpad/8", QRect(563, 9, 152, 193));
		mConfig->setValue("Numpad/9", QRect(725, 9, 152, 193));
		mConfig->setValue("Numpad/4", QRect(401, 212, 152, 193));
		mConfig->setValue("Numpad/5", QRect(563, 212, 152, 193));
		mConfig->setValue("Numpad/6", QRect(725, 212, 152, 193));
		mConfig->setValue("Numpad/1", QRect(401, 415, 152, 193));
		mConfig->setValue("Numpad/2", QRect(563, 415, 152, 193));
		mConfig->setValue("Numpad/3", QRect(725, 415, 152, 193));
		mConfig->setValue("Numpad/0", QRect(401, 618, 152, 193));
		mConfig->setValue("Numpad/delete", QRect(563, 618, 152, 193));
		mConfig->setValue("Numpad/return", QRect(725, 618, 152, 193));

		mConfig->setValue("Simulation/enabled", false);
		mConfig->setValue("Simulation/minItems", 10);
		mConfig->setValue("Simulation/maxItems", 20);
		mConfig->setValue("Simulation/maxFriday", 50);
		mConfig->setValue("Simulation/maxSaturday", 50);
		mConfig->setValue("Simulation/maxSunday", 50);
		mConfig->setValue("Simulation/maxTombolaInserts", 50);
		mConfig->setValue("Simulation/maxTombolaNumber", 100);

		mConfig->setValue("Stats/timeDiff", 30);

		mConfig->setValue("Diagram/margin", 50);
		mConfig->setValue("Diagram/spaceBetween", 40);
		mConfig->setValue("Diagram/heightBetween", 20);

		mConfig->setValue("Print/margin", QRect(5, 5, 200, 287));
		mConfig->setValue("Print/size", QSize(50, 10));
		mConfig->setValue("Print/fontSize", 15);

		mConfig->sync();
	}
}

void Config::destroy() {
	delete mConfig;
}

QVariant Config::get(const QString& category, const QString& name) {
	return mConfig->value(category + "/" + name);
}

void Config::set(const QString& category, const QString& name, const QVariant& value) {
	mConfig->setValue(category + "/" + name, value);
}

void Config::sync() {
	mConfig->sync();
}

}
}